package com.hnchances.studentscoresystem.service.impl;

import com.hnchances.studentscoresystem.entity.Course;
import com.hnchances.studentscoresystem.mapper.CourseMapper;
import com.hnchances.studentscoresystem.service.CourseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程管理 Service 实现类
 */
@Service
public class CourseServiceImpl extends BaseServiceImpl<Course, Integer, CourseMapper> implements CourseService {

    @Override
    public boolean insert(Course course) {
        // 补全默认值：状态默认为 0（正常）
        if (course.getStatus() == null) {
            course.setStatus(0);
        }
        return mapper.insert(course) > 0;
    }

    @Override
    public Course selectById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Course> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public boolean update(Course course) {
        return mapper.update(course) > 0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) > 0;
    }

    @Override
    public Course selectByCourseName(String courseName) {
        List<Course> courseList = mapper.selectByNameLike(courseName);
        return courseList.isEmpty() ? null : courseList.get(0);
    }
}